Skip to content

Refactor tests of xc module#7475

Open
mohanchen wants to merge 4 commits into
deepmodeling:developfrom
mohanchen:20260616-2
Open

Refactor tests of xc module#7475
mohanchen wants to merge 4 commits into
deepmodeling:developfrom
mohanchen:20260616-2

Conversation

@mohanchen

Copy link
Copy Markdown
Collaborator

No description provided.

abacus_fixer added 2 commits June 16, 2026 22:28
This commit decouples XC_Functional and related libxc functions from the global PARAM object by adding explicit parameters:

1. Modified XC_Functional::v_xc() to accept nspin, domag, domag_z parameters instead of accessing PARAM
2. Modified XC_Functional::gradcorr() to accept nspin, domag, domag_z parameters
3. Modified XC_Functional::set_xc_type() to accept nspin parameter
4. Modified XC_Functional_Libxc::v_xc_libxc() to accept nspin, domag, domag_z parameters
5. Modified XC_Functional_Libxc::v_xc_meta() to accept nspin parameter

Updated all call sites in:
- source_estate/module_pot/pot_xc.cpp
- source_estate/module_pot/pot_xc_fdm.cpp
- source_pw/module_pwdft/forces_cc.cpp
- source_pw/module_pwdft/stress_cc.cpp
- source_hamilt/module_xc/xc_pot.cpp
- source_hamilt/module_xc/libxc_pot.cpp
- source_hamilt/module_xc/libxc_abacus.h

Updated test files to remove PARAM dependencies:
- test_xc3.cpp: Removed PARAM include and initialization
- test_xc5.cpp: Removed PARAM include and initialization, updated v_xc, v_xc_meta calls
- xctest.h: Removed PARAM include and initialization

Default parameter values are provided for backward compatibility.
@mohanchen mohanchen added Refactor Refactor ABACUS codes Tests/Examples Issues/PR related to unit tests and integrate tests The Absolute Zero Reduce the "entropy" of the code to 0 labels Jun 17, 2026
abacus_fixer added 2 commits June 17, 2026 09:04
…prove parameter passing

Summary of changes:

1. Modified libxc_abacus.h:
   - Removed default value (=1) for nspin parameter in v_xc_libxc
   - Removed default value (=nullptr) for scaling_factor parameter in v_xc_libxc

2. Modified xc_functional.h:
   - Changed set_xc_type signature to only accept const std::string xc_func_in
   - Removed nspin and basis_type parameters from set_xc_type
   - Removed default parameters from v_xc and gradcorr

3. Modified xc_functional.cpp:
   - Updated set_xc_type implementation to match new signature
   - Removed meta-GGA nspin=4 check from set_xc_type (moved to gradcorr)
   - Removed hybrid functional LCAO check from set_xc_type (no longer needed)
   - Updated internal set_xc_type calls to use single parameter

4. Modified xc_grad.cpp:
   - Added meta-GGA nspin=4 check at the beginning of gradcorr function
   - This is the correct place for runtime validation since nspin is known here

5. Modified xc_pot.cpp:
   - Updated v_xc_libxc call to pass parameters correctly

6. Modified libxc_pot.cpp:
   - Updated v_xc_libxc implementation to match new signature

7. Modified stress_gga.cpp:
   - Changed direct 'true' argument to named variable 'is_stress' for gradcorr call
   - Improved code readability and maintainability

8. Updated all set_xc_type call sites (12 files):
   - test_xc.cpp, test_xc1.cpp, test_xc2.cpp, test_xc3.cpp, test_xc5.cpp
   - xc_functional.cpp, esolver_double_xc.cpp, esolver_ks_lcaopw.cpp
   - esolver_fp.cpp, Exx_LRI_interface.hpp, xc_kernel.cpp, exx_helper.cpp
   - All calls now pass only the xc_func_in parameter

9. Updated test_xc3.cpp and test_xc5.cpp:
   - Added named variables (nspin1, nspin2, nspin4, domag, domag_z, domag_true)
   - Removed direct numeric literals in function calls

Rationale:
- Separated functional setup (set_xc_type) from runtime configuration (nspin, basis_type)
- Runtime validation checks moved to actual computation functions (gradcorr)
- Parameter passing improved with meaningful variable names instead of magic numbers
- Code readability and maintainability enhanced
- Preparation for future improvements to XC functional interface
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Refactor Refactor ABACUS codes Tests/Examples Issues/PR related to unit tests and integrate tests The Absolute Zero Reduce the "entropy" of the code to 0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant